NPU Errors

Niklas Heim
7th May 2020
Plots.PlotlyBackend()
nacmult(x,w;ϵ=1f-7) = exp(w * log(abs(x + ϵ)))

function npu(x::T, w::T; e::T=T(0.05)) where T
    r = abs.(x)
    k = T(x < 0 ? pi : 0.0)
    if r < e && abs(w) < e
        T(1)
    else
        return exp(w * log(r)) * cos(w*k)
    end
end;

Error surface of NPU to the identity when w ≈ 1

id_mse(x,w) = abs(x^w - npu(x,w))
f(x,w) = min(id_mse(x,w), 2)

x = 0:0.01:1
w = 0.9:0.001:1.1

surface(x, w, (x,w)->f(x,w), xlabel="x", ylabel="w")
Plots.jl

Error surface of NPU to the identity when w ≈ 0

id_mse(x,w) = abs(x^w - npu(x,w))
f(x,w) = min(id_mse(x,w), 2)

x = 0:0.001:0.1
w = -0.1:0.001:0.1
surface(x, w, (x,w)->f(x,w), xlabel="x", ylabel="w")
Plots.jl
function npu(x::T, w::T, g::T) where T
    r = abs.(x)
    k = T(x < 0 ? pi : 0.0)
    z = exp(w * log(r)) * cos(w*k)
    return g*z + (1-g)*x
end

f(x,w,g) = abs(x^w-npu(x,w,g))
#f(x,w,g) = abs(x-npu(x,w,g))

x = 0:0.001:0.1
w = 0:0.001:0.1
p1 = heatmap(x, w, (x,w)->f(x,w,1.0), title="g=1",   clim=(0,1))
p2 = heatmap(x, w, (x,w)->f(x,w,0.5), title="g=0.5", clim=(0,1))
p3 = heatmap(x, w, (x,w)->f(x,w,0.1), title="g=0.1", clim=(0,1))
p4 = heatmap(x, w, (x,w)->f(x,w,0.0), title="g=0.0", clim=(0,1))
plot(p1,p2,p3,p4)
Plots.jl
x = 0:0.001:0.1
w = 0.9:0.001:1.1
p1 = heatmap(x, w, (x,w)->f(x,w,1.0), title="g=1",   clim=(0,1e-2))
p2 = heatmap(x, w, (x,w)->f(x,w,0.5), title="g=0.5", clim=(0,1e-2))
p3 = heatmap(x, w, (x,w)->f(x,w,0.1), title="g=0.1", clim=(0,1e-2))
p4 = heatmap(x, w, (x,w)->f(x,w,0.0), title="g=0.0", clim=(0,1e-2))
plot(p1,p2,p3,p4)
Plots.jl
# x = -1:0.01:1
# p2 = plot(x, x -> nacmult(x,1) - x, label="nac")
# plot!(p2, x, x -> npu(x,1) - x, label="npu")